<!--
* description: 回收网点入库信息详情
* author: hzm
* createdDate: 2021-4-29
-->
<template>
  <section class="editBigAreaInfo">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap"
      :append-to-body="true"
      :visible.sync="popupsTime"
      width="70%"
      @close="closeEdit"
      @open="open"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />

      <one-table-template
        ref="multipleTable1"
        :dynamic-buttons="tableButtons1"
        :dynamic-components="tableComponents1"
        :dynamic-api-style="'restful'"
      />
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from '@/components/mixins/formMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { orgApis } from '@/api/paSparePartsManagement'
export default {
  components: {
    OneTableTemplate,
    dialogHeader: () => import('@/components/dialogHeader'),
    mixButton: () => import('@/components/basicComponent/mixButton')
  },
  // 组件混入对象
  mixins: [formMixins],
  props: {
    popupsTime: { type: Boolean, default: false }
    // 从网格传入的编辑行数据(json)
    // dynamicEditRowData: { type: Object, default: function() { return {} } }
  },
  data() {
    const viewPageCode = 'bigAreaInfo-edit'
    return {
      selectiondata: null,
      dynamicApiConfigs: orgApis.shortageAuditMoreList,
      // 动态组件-按钮
      tableButtons1: [
        {
          compKey: 'btnKey6',
          type: 'primary',
          size: 'small',
          icon: '',
          //   clickEvent: () => this.editReject(1),
          text: '提交',
          position: 'right'
        },
        {
          compKey: 'btnKey6',
          type: '',
          size: 'small',
          icon: '',
          clickEvent: () => this.editReject(2),
          text: '取消',
          position: 'right'
        }
      ],

      // 标题
      textMap: '回收网点入库信息详情',

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(this, {
        lackPartsCode: '',
        associationType: '',
        associationNo: '',
        lackPartsSource: '',
        carLicense: '',
        vin: '',
        customerName: '',
        customerPhone: '',
        registerPerson: '',
        urgency: '',
        remark: '',
        lackPartsId: '',
        updateControlId: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },
  mounted() {
    console.log(this.dynamicEditRowData)
  },
  methods: {
    // 关闭弹窗
    // handleClose(done) {
    //   this.$confirm('还未保存，确认关闭窗口？')
    //     .then(_ => {
    //       this.$emit('update:popupsVisible', false)
    //       done()
    //     })
    //     .catch(_ => {})
    // },
    open() {
      this.$refs['multipleTable'].queryTable()
    },
    closeEdit() {
      this.$emit('update:popupsVisible', false)
    },
    // 新增/编辑保存按钮
    // save() {
    //   const that = this
    //   this.$utils.validataMoth(this, 'validpopup')
    //   if (this.valid) {
    //     if (that.popupsState === 'edit') {
    //       that.editSave()
    //     } else {
    //       that.addSave()
    //     }
    //   }
    // },
    // 驳回
    editReject(num) {
      const that = this
      const checkBox = { list: [] }
      checkBox.list = this.$refs['multipleTable'].list
      const queryObj = {
        apiConfig: orgApis.shortageAuditMoreListRejectedby,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: checkBox
      }
      if (num == 1) {
        queryObj.apiConfig = orgApis.shortageAuditMoreListExamine
        checkBox.lackPartsId = this.dynamicEditRowData.lackPartsId

        // this.selectiondata.forEach(function(val, index) {
        //   checkBox.list.push({
        //     lackPartsDId : val.LACK_PARTS_D_ID,
        //   })
        // })
      } else if (num == 2) {
        queryObj.apiConfig = orgApis.shortageAuditMoreListRejectedby
        // this.selectiondata.forEach(function(val, index) {
        //   checkBox.list.push({
        //     lackPartsDId : val.LACK_PARTS_D_ID,
        //   })
        // })
      }

      console.log(checkBox, this.selectiondata, 'checkBox')

      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result === '1') {
          this.$message({
            message: this.$t('sys.tips.esTip5'),
            type: 'success',
            duration: 1000
          })
          this.popupsVisible = false
          this.$nextTick(() => {
            this.$parent.queryTable(1)
          })
        } else {
          // 保存失败
          this.$message({
            message: response.msg,
            type: 'warn',
            uration: 1000
          })
        }
        this.popupsVisible = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.promptSpan {
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
</style>

